<template>
  <div :class="prefixCls">
    <BasicTable @register="registerTable" :rowSelection="rowSelection" v-bind="$attrs">
      <template #tableTitle>
        <a-button preIcon="ant-design:highlight" type="primary" @click="onShowCustomButton">自定义按钮</a-button>
        <a-button preIcon="ant-design:strikethrough" type="primary" @click="onShowEnhanceJs">JS增强</a-button>
        <a-button preIcon="ant-design:filter" type="primary" @click="onShowEnhanceSql">SQL增强</a-button>
        <a-button preIcon="ant-design:tool" type="primary" @click="onShowEnhanceJava">JAVA增强</a-button>
      </template>

      <template #dbSync="{ text }">
        <span v-if="text === 'Y'" style="color: limegreen">已同步</span>
        <span v-if="text === 'N'" style="color: red">未同步</span>
      </template>

      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
      </template>
    </BasicTable>
  </div>
  <CgformModal @register="registerCgformModal" actionButton="false" @success="reload" />
  <DbToOnlineModal @register="registerDbToOnlineModal" @success="reload" />
  <CustomButtonList @register="registerCustomButtonModal" />
  <EnhanceJsModal @register="registerEnhanceJsModal" />
  <EnhanceSqlModal @register="registerEnhanceSqlModal" />
  <EnhanceJavaModal @register="registerEnhanceJavaModal" />
  <AuthManagerDrawer @register="registerAuthManagerDrawer" />
  <AuthSetterModal @register="registerAuthSetterModal" />
</template>
<script lang="ts">
  import { defineComponent, provide, watch } from 'vue';
  import { BasicTable, TableAction } from '/@/components/Table';

  import CgformModal from './components/CgformModal.vue';
  import DbToOnlineModal from './components/DbToOnlineModal.vue';
  import CustomButtonList from './components/button/CustomButtonList.vue';
  import EnhanceJsModal from './components/enhance/EnhanceJsModal.vue';
  import EnhanceJavaModal from './components/enhance/EnhanceJavaModal.vue';
  import EnhanceSqlModal from './components/enhance/EnhanceSqlModal.vue';
  import AuthManagerDrawer from './components/auth/AuthManagerDrawer.vue';
  import AuthSetterModal from './components/auth/AuthSetterModal.vue';

  import { useCgformList, CgformPageType } from './use/useCgformList';

  export default defineComponent({
    name: 'CgformCopyList',
    components: {
      BasicTable,
      TableAction,
      CgformModal,
      DbToOnlineModal,
      CustomButtonList,
      EnhanceJsModal,
      EnhanceJavaModal,
      EnhanceSqlModal,
      AuthManagerDrawer,
      AuthSetterModal,
    },
    setup() {
      const pageType = CgformPageType.copy;
      provide('cgformPageType', pageType);
      const {
        router,
        pageContext,
        getTableAction,
        getDropDownAction,
        onShowCustomButton,
        onShowEnhanceJs,
        onShowEnhanceSql,
        onShowEnhanceJava,
        registerCustomButtonModal,
        registerEnhanceJsModal,
        registerEnhanceSqlModal,
        registerEnhanceJavaModal,
        registerAuthManagerDrawer,
        registerAuthSetterModal,
        registerCgformModal,
        registerDbToOnlineModal,
      } = useCgformList({
        pageType,
        designScope: 'online-cgform-list',
        columns: [
          { title: '视图表名', dataIndex: 'tableName' },
          { title: '视图表描述', dataIndex: 'tableTxt' },
          { title: '原表版本', dataIndex: 'copyVersion' },
          { title: '视图版本', dataIndex: 'tableVersion' },
        ],
        formSchemas: [{ label: '表名', field: 'tableName', component: 'JInput' }],
      });
      const { prefixCls, tableContext } = pageContext;
      const [registerTable, { reload }, { rowSelection }] = tableContext;
      watch(router.currentRoute, () => reload());
      return {
        prefixCls,
        reload,
        rowSelection,
        getTableAction,
        getDropDownAction,
        onShowCustomButton,
        onShowEnhanceJs,
        onShowEnhanceSql,
        onShowEnhanceJava,
        registerCustomButtonModal,
        registerEnhanceJsModal,
        registerEnhanceSqlModal,
        registerEnhanceJavaModal,
        registerAuthManagerDrawer,
        registerAuthSetterModal,
        registerTable,
        registerCgformModal,
        registerDbToOnlineModal,
      };
    },
  });
</script>
